home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_1 / dragon.cur < prev    next >
Text File  |  1995-03-23  |  3KB  |  174 lines

  1. Article 2431 of comp.sys.handhelds:
  2. Path: en.ecn.purdue.edu!noose.ecn.purdue.edu!mentor.cc.purdue.edu!purdue!bu.edu!rpi!dali.cs.montana.edu!milton!cmeyer
  3. From: cmeyer@milton.u.washington.edu (Colin Meyer)
  4. Newsgroups: comp.sys.handhelds
  5. Subject: Dragon Curves on the HP48SX
  6. Message-ID: <11340@milton.u.washington.edu>
  7. Date: 18 Nov 90 20:41:30 GMT
  8. Distribution: comp.sys.handhelds
  9. Organization: University of Washington, Seattle
  10. Lines: 160
  11.  
  12.  
  13.  
  14. Here is a program to draw dragon curves on the HP48SX.
  15.  
  16. Dragon curves? Yeah, those things that you make by folding a strip of 
  17. paper in half n times & then unfolding it so all the corners are right
  18. angles.
  19.  
  20. Programs:
  21.  
  22.     DRAGON: generates a dragon curve of order n (n >= 3).
  23.     SKETCH: draws a dragon curve.
  24.     DRAWC:  (called by SKETCH).
  25.  
  26. Usage:
  27.  
  28. DRAGON: 
  29.  
  30.     1: n
  31.  
  32. Press [DRAGON]. N must be 3 or greater. Dragon returns a string of ones
  33. and zeros to 1:. A zero is a left turn & a one is a right turn.
  34.  
  35. SKETCH:
  36.  
  37.     3: "0010011..." (a dragon curve)
  38.     2: start
  39.     1: r
  40.  
  41. Press [SKETCH]. The string in level 3 is a string generated by DRAGON.
  42. Start in level 2 is the point to start drawing from. It can be in complex 
  43. number form or in a list of binary integers (user units or pixels).
  44. R in level one is the radius of the corners (each corner is a quarter circle).
  45.  
  46. Note: the User Units must be in the same ration of x to y as the pixels in 
  47. PICT. The easiest way to get this is to make the user units the same as the
  48. pixels.  For examle, if PICT is #131 by #150, make the xrange 0..131 and the
  49. yrange 0..150.
  50.  
  51. Example:
  52.  
  53. First, do #131 #150 pdim. Then do 0 131 xrng 0 150 yrng.
  54.  
  55. 1: 8
  56. [DRAGON]
  57.  
  58.  
  59. 3: "0010011..." (the string generated by DRAGON)
  60. 2: { # 65d # 33d }
  61. 1: 3
  62.  
  63. [SKETCH]
  64.  
  65. (Sit back and enjoy.)
  66.  
  67.  
  68. Code:
  69.  
  70. BYTES:
  71. # E34Ch
  72. 1202.5
  73.  
  74. -------cut here--------
  75. %%HP: T(3)A(D)F(.);
  76. DIR
  77.   DRAGON
  78.     \<<
  79.       IF DUP 3 ==
  80.       THEN DROP
  81. "0010011"
  82.       ELSE 1 -
  83. DRAGON DUP DUP SIZE
  84. DUP 1 + 2 / 1 +
  85. SWAP SUB OVER 0 + \->
  86. old oldh new
  87.         \<< 1 oldh
  88. SIZE
  89.           FOR j old
  90. j j SUB OBJ\-> R\->B
  91. oldh j j SUB OBJ\->
  92. R\->B AND B\->R new
  93. SWAP + 'new' STO
  94.           NEXT new
  95. 1 + oldh +
  96.         \>>
  97.       END
  98.     \>>
  99.   SKETCH
  100.     \<< ERASE { # 0d
  101. # 0d } PVIEW # 0d
  102. SWAP R\->B 2 \->LIST
  103. PX\->C { # 0d # 0d }
  104. PX\->C - ABS SWAP 3
  105. ROLLD \-> drgn d
  106.       \<<
  107.         IFERR PX\->C
  108.         THEN
  109.         END 4 1
  110. drgn SIZE
  111.         FOR j drgn
  112. j j SUB
  113.           IF "0"
  114. SAME
  115.           THEN
  116.             CASE
  117. DUP 1 ==
  118.               THEN
  119. DROP 0 d 270 0 d
  120. DUP DUP DRAWC 2
  121.               END
  122. DUP 2 ==
  123.               THEN
  124. DROP d NEG 0 0 90 d
  125. DUP NEG d DRAWC 3
  126.               END 3
  127. ==
  128.               THEN
  129. 0 d NEG 90 180 d d
  130. NEG DUP DRAWC 4
  131.               END d
  132. 0 180 270 d DUP DUP
  133. NEG DRAWC 1
  134.             END
  135.           ELSE
  136.             CASE
  137. DUP 1 ==
  138.               THEN
  139. DROP 0 d NEG 0 90 d
  140. DUP DUP NEG DRAWC 4
  141.               END
  142. DUP 2 ==
  143.               THEN
  144. DROP d 0 90 180 d
  145. DUP DUP DRAWC 1
  146.               END 3
  147. ==
  148.               THEN
  149. 0 d 180 270 d DUP
  150. NEG d DRAWC 2
  151.               END d
  152. NEG 0 270 0 d DUP
  153. NEG DUP DRAWC 3
  154.             END
  155.           END
  156.         NEXT DROP2
  157.       \>>
  158.     \>>
  159.   DRAWC
  160.     \<< \-> x y a b r s
  161. t
  162.       \<< DUP x y R\->C
  163. + r a b ARC s t R\->C
  164. +
  165.       \>>
  166.     \>>
  167.   PPAR { (0,0)
  168. (131,150) X 0 (0,0)
  169. FUNCTION Y }
  170. END
  171. -------end cut-------
  172.  
  173.  
  174.